// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SyndicationFeedResult.cs" company="ecblog.codeplex.com">
//   emrecoskun.net - ibrahimatay.com
// </copyright>
// <summary>
//   Syndication Feed Result
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace EcBlog.Controllers
{
    using System.IO;
    using System.ServiceModel.Syndication;
    using System.Web.Mvc;
    using System.Xml;

    /// <summary>
    /// Syndication Feed Result
    /// </summary>
    public class SyndicationFeedResult : ContentResult
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SyndicationFeedResult"/> class.
        /// </summary>
        /// <param name="feed">The feed.</param>
        public SyndicationFeedResult(SyndicationFeed feed)
        {
            using (var memstream = new MemoryStream())
            using (var writer = new XmlTextWriter(memstream, System.Text.Encoding.UTF8))
            {
                feed.SaveAsRss20(writer);
                writer.Flush();
                memstream.Position = 0;
                this.Content = new StreamReader(memstream).ReadToEnd();
                this.ContentType = "application/rss+xml";
            }
        }
    }
}